<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$id = get_input('id');
$adjective = get_input('adjective');
$adjective_url = get_input('adjective_url');
$adjective_thumbnail_url = get_input('adjective_thumbnail_url');
$adjective_coin = 10;//get_input('adjective_coin');

$user_id = get_loggedin_userid();
if(dt_update_game($id, $adjective, $adjective_url, $adjective_thumbnail_url, $adjective_coin)) {
    $game = dt_get_game($id);
    //var_dump($game);
    $game = dt_get_game($id);
    $noun_user = dt_get_user_by_user_id($game->noun_id);
    $adjective_user = dt_get_user_by_user_id($game->adjective_id);
    $noun_name = $noun_user->fullname;
    $adjective_name = $adjective_user->fullname;
    $noun = $game->noun;
    $adjective = $game->adjective;
    $message = "Hey $noun_name, $adjective_name just turned your $noun into \"$adjective $noun\", come and see!";
    //dt_send_push_notification($game->noun_id, $message, TRUE);
    //dt_send_push_notification($game->noun_id, $message, FALSE);
    dt_update_coins($user_id, $adjective_coin);
    dt_create_game_holder($user_id, $game->noun_id, $id, $game->turn+1);
    echo json_encode(export_result(200, "1"));
} else {
    echo json_encode(export_result(400, "0"));
}
?>
